package com.zh.note.huawei.onehundred.字母消消乐;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner s = new Scanner(System.in)) {
            // String str = s.nextLine();
            String str ="mMbccbc";
            solveMethod(str);
        }
    }


    private static void solveMethod(String str) {
        // 如果输入字符串为空或长度为0，则输出0并返回
        if (str == null || str.isEmpty()) {
            System.out.println(0);
            return;
        }

        // 如果输入字符串中包含字母，则输出0并返回
        String s = str.replaceAll("[a-zA-Z]", "");
        if (s.length() > 0) {
            System.out.println(0);
            return;
        }

        StringBuilder sb = new StringBuilder();
        char prev = '\0';
        for (char c : str.toCharArray()) {
            if (c != prev) {
                sb.append(c);
                prev = c;
            } else {
                sb.deleteCharAt(sb.length() - 1);
                prev = sb.length() == 0 ? '\0' : sb.charAt(sb.length() - 1);
            }
        }

        // 输出去重后的字符串长度
        System.out.print(sb.length());
    }
}

